<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
    function addPrint() {
        var obj=document.getElementsByName('ppid[]');
        var chk_value =[];
        var s= "";
        for (var i=0;i<obj.length;i++)
        {
            if(obj[i].checked) s+=obj[i].value+','; //如果选中，将value添加到变量s中
        }
        //alert(s);return false;
        if(s){
            var url ="/applybuy/ajaxbutton?op=applyBuyPrint&param="+s;
            //var url ='http://'+window.location.host+'/applybuy/applyBuyPrint?param='+s;
            //location.href= url;
            window.open(url);
        }else{
            alert("请选择需要打印的订单!");return false;
        }

    }
    //需要对有些进行验证
    function batchremit() {
        var obj = document.getElementsByName('ppid[]');
        var chk_value = [];
        var s = "";
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked) s += obj[i].value + ','; //如果选中，将value添加到变量s中
        }
        if (s) {
            $.post("/applybuy/applyBatchRemit",{param:s}, function (data) {
                if (data.code) {
                    //location.reload();
                    window.location.href = "/applybuy/applyRemitList";
                } else {
                    alert(data.msg);
                    return false;
                }
            }, "json");



            //var url = 'http://' + window.location.host + '/applybuy/applyBatchRemit?param=' + s;
            //location.href= url;
           // window.open(url);
        } else {
            alert("请选择需要操作的订单!");
            return;

        }
    }
    //申请打款
    function remit(id) {
        if(confirm("你确定申请打款？")) {
            $.post("/applybuy/applyBatchRemit",{param:id}, function (data) {
              //  $.post("/applybuy/applyRemit",{id:id}, function (data) {
                if (data.code) {
                    //location.reload();
                    window.location.href = "/applybuy/applyRemitList";
                } else {
                    alert(data.msg);
                    return false;
                }
            }, "json");
        }
    }
    //订单作废
    function cancel(id) {
        if(confirm("你确定作废订单？")){
            $.post("/applybuy/cancelOrder",{id:id},function(data){
                if(data.code)
                {
                    location.reload();
                }else{
                    alert(data.msg);return false;
                }
            },"json");
        }
    }


</script>
<title>采购申请列表</title>
<body class="withvernav">
<div class="bodywrapper">
    {{include file='/public/leftmenu.tpl'}}
    <div class="centercontent">
        <div class="pageheader notab">
            <h1 class="pagetitle">采购申请列表</h1>
            <span class="pagedesc"></span>
            <div class="menulist">
                <ul class="profile_summary">
                    {{if $managers || in_array('257',$showpower)}}  <li> <a href="/applybuy/addApplyBuy" ><span>添加</span></a></li>{{/if}}
                </ul>
            </div>

        </div>
        <!--pageheader-->
        <div id="contentwrapper" class="contentwrapper">
            <div id="basicform" class="subcontent">
                <!--搜索栏-->
                <div>
                    <div class="page">{{$pageList}} 计{{$total}}条记录，共{{$totalpage}}页</div>
                </div>
                <form class="stdform stdform2" method="get" id="search" action="/applybuy/applyList">
                    <div class="tableoptions">
                        名称：
                        <input type="text" name="name" id="name" class="width200" value="{{$name}}" placeholder="请输入名称" style="width:120px;"/>
                        批次：
                        <input type="text" name="pici" id="pici" class="width200" value="{{$pici}}" placeholder="请输入批次" style="width:120px;"/>
                        供应商：
                        <select class="selectCss2" name="search_supplier" id="search_supplier">
                            <option value="">请选择</option>
                            {{foreach from=$suppliers item=res key=key}}
                            <option value="{{$res.id}}" {{if $search_factory eq {{$res.id}}}}selected{{/if}}> {{$res.name}} </option>
                            {{/foreach}}
                        </select>
                        工厂：
                        <select class="selectCss2" name="search_factory" id="search_factory">
                            <option value="">请选择</option>
                            {{foreach from=$factorys item=res key=key}}
                            <option value="{{$res.id}}" {{if $search_factory eq {{$res.id}}}}selected{{/if}}> {{$res.name}} </option>
                            {{/foreach}}
                        </select>
                        <select name="search_status" id="search_status"  class="selection select2_group" style="width:120px;" >
                            <option value="" >状态</option>
                            <option value="1" {{if $search_status eq 1}}selected{{/if}}>新创建</option>
                            <option value="2" {{if $search_status eq 2}}selected{{/if}}>申请打款</option>
                            <option value="3" {{if $search_status eq 3}}selected{{/if}}>打款完成</option>
                            <option value="4" {{if $search_status eq 4}}selected{{/if}}>作废</option>
                        </select>
                        <button class="btn btn_orange btn_search radius50">查询</button>
                        <a href="javascript:void();" onclick="addPrint()">
                            <button class="btn btn_orange btn_search radius50" >打印</button>
                        </a>

                        <a href="javascript:void();" onclick="batchremit()">
                            <button class="btn btn_orange btn_search radius50">批量申请打款</button>
                        </a>

                    </div>
                </form>
                <!--搜索栏结束-->
                <table cellpadding="0" cellspacing="0" border="0" class="stdtable">
                    <thead>
                    <tr class="lbbt">
                        <td class="head0">
                            <a onClick="allSelect('ppid[]')">全选<input type="checkbox"></a>
                        </td>
                        <td  bgcolor="#FEFFF1">序号</td>
                        <td  bgcolor="#FEFFF1">名称</td>
                        <td  bgcolor="#FEFFF1">数量</td>
                        <td  bgcolor="#FEFFF1">单价/单位</td>
                        <td  bgcolor="#FEFFF1">供应商</td>
                        <td  bgcolor="#FEFFF1">状态</td>
                        <td  bgcolor="#FEFFF1">批次</td>
                        <td  bgcolor="#FEFFF1">工厂</td>
                        <td  bgcolor="#FEFFF1">备注</td>
                        <td  bgcolor="#FEFFF1">操作人</td>
                        <td  bgcolor="#FEFFF1">操作时间</td>
                        <td  bgcolor="#FEFFF1">操作</td>
                    </tr>
                    </thead>
                    <tbody >

                    {{foreach from=$orderlist item=li key=key}}
                    <tr>
                        <td class="head0"><input name="ppid[]" type="checkbox" class="none" id="ppid[]" value="{{$li.id}}"/></td>
                        <td valign="middle"  style="position:relative;">
                            {{$li.id}}
                        </td>
                        <td valign="middle" bgcolor="#FFFFFF">
                            {{$li.name}}
                        </td>
                        <td valign="middle" bgcolor="#FFFFFF">
                            {{$li.quantity}}
                        </td>
                        <td valign="middle" bgcolor="#FFFFFF">
                            {{$li.price}}/{{$li.unit}}
                        </td>
                        <td valign="middle" bgcolor="#FFFFFF">
                            {{$li.supplier_name}}
                        </td>
                        <td valign="middle" bgcolor="#FFFFFF">
                            {{if $li.status eq 1}}
                            新创建
                            {{elseif $li.status eq 2}}
                            申请打款
                            {{elseif $li.status eq 3}}
                            打款完成
                            {{elseif $li.status eq 4}}
                            作废
                            {{else}}
                            {{/if}}
                        </td>
                        <td valign="middle" bgcolor="#FFFFFF">
                            {{$li.groupid}}
                        </td>
                        <td valign="middle" bgcolor="#FFFFFF">
                            {{$li.factory_name}}
                        </td>
                        <td bgcolor="#FFFFFF" style="position:relative;">
                            {{$li.remark}}
                        </td>
                        <td bgcolor="#FFFFFF" style="position:relative;">
                            {{$li.user_name}}
                        </td>
                        <td bgcolor="#FFFFFF" class="cz">
                            {{$li.opertime}}
                        </td>
                        <td bgcolor="#FFFFFF" class="cz">
                            {{if $li.status eq 1}}
                                <a href="/applybuy/edit?id={{$li.id}}">编辑</a>
                                <a href="javascript:void(0)" onclick="remit({{$li.id}})">申请打款</a>
                                <a href="javascript:void(0)" onclick="cancel({{$li.id}})">作废</a>
                            {{else}}
                            {{/if}}
                        </td>
                    </tr>
                    {{/foreach}}
                    </tbody>
                </table>
                <div class="page">{{$pageList}} 计{{$total}}条记录，共{{$totalpage}}页</div>
            </div>
        </div>
</body>
</html>